package top.wshape1.shiziapi.project.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-08-27
 */

@Configuration
@ConfigurationProperties(prefix = "async.executor.thread")
@Data
public class ThreadPoolConfig {

    private Integer coreSize;

    private Integer maxSize;

    private Integer keepAliveTime;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
                getCoreSize(),
                getMaxSize(),
                getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
